app.controller('registerPageCtrl',
    function($ionicBackdrop, $ionicConfig,$interval,$myconfig, $http,$scope, $state, $ionicSideMenuDelegate, $ionicHistory, $ionicPopup, BthSevice, PopupService ,$mydialog) {

        //用户注册预置空对象
        $scope.GoUser = {
            mobile:'',
            password:''
        };

    //验证码时效倒计时
    $scope.secend = 60;
    $scope.seBtn = true;

    //用户获取验证码
    $scope.registerGo = function(){
        $http.post($myconfig.api.base_host + '/users/get_code' , {
            mobile : $scope.GoUser.mobile,
            code_type :'register'
        }).then(function(res){
            // $scope.registerListData = res.data.data;
            // console.log(res.data);
            if(res.data.success){
                $scope.seBtn = false;
                $interval(function(){
                    $scope.secend--
                    if($scope.secend == 0){
                        $scope.seBtn = true;
                        $scope.secend = 60;
                    }
                },1000,60);
             }else{
                 $scope.err = res.data.data;
                $mydialog.fail($scope);
            }
        });
    };

    //切换下一页面
    $scope.GOPer = function(){
        // console.log($scope.GoUser);
        if(!$scope.GoUser.password){
            $scope.err = '请输入密码，且不得少于八位';
            $mydialog.fail($scope);
            return;
        }else if(!$scope.GoUser.comf_password){
            $scope.err = '请再次输入密码';
            $mydialog.fail($scope);
            return;
        }else if($scope.GoUser.password != $scope.GoUser.comf_password){
            $scope.err = '两次密码不匹配，请重新输入';
            $mydialog.fail($scope);
            return;
        }
        $http.post($myconfig.api.base_host + '/users/verify' , {
            "code":$scope.GoUser.code,
            "mobile":$scope.GoUser.mobile,
            "code_type":'register'
        }).then(function(res){
            if(res.data.success){
                $state.go('app.perfectinfo',{next:JSON.stringify($scope.GoUser)});
            }else{
                $mydialog.fail($scope);
                $scope.err = res.data.data;
            }
        });
    };
    $scope.$on('$ionicView.enter', function(){

        $ionicConfig.views.swipeBackEnabled(false);

    });


        //向服务器请求数据内容
    $scope.aboutUs = function(){
        $http.get($myconfig.api.base_host + '/basicinformation/APP_info')
        .then(function(res){
            if(res.data.success){
                $scope.aboutUsData = res.data.data;
                $state.go('app.setup_about_service',{Mes:JSON.stringify($scope.aboutUsData.agreement[0])}); //服务协议
            }else{
                $scope.err = res.data.data;
            }
        });
    };


    // $scope.Gonext = function(){
    //         $scope.aboutUs();
    // };

});
